home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / TCPTIMER.C < prev    next >
C/C++ Source or Header  |  1988-03-05  |  1KB  |  56 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. /* Timer timeout */
  11. void
  12. tcp_timeout(arg)
  13. char *arg;
  14. {
  15.     register struct tcb *tcb;
  16.  
  17.     tcb = (struct tcb *)arg;
  18.  
  19.     if(tcb == NULLTCB)
  20.         return;
  21.  
  22.     /* Make sure the timer has stopped (we might have been kicked) */
  23.     stop_timer(&tcb->timer);
  24.  
  25.     switch(tcb->state){
  26.     case TIME_WAIT:        /* 2MSL timer has expired */
  27.         close_self(tcb,NORMAL);
  28.         break;
  29.     default:        /* Retransmission timer has expired */
  30.         tcb->flags |= RETRAN;    /* Indicate > 1  transmission */
  31.         tcb->backoff++;
  32.         tcb->snd.ptr = tcb->snd.una;
  33.         /* Reduce slowstart threshold to half current window */
  34.         tcb->ssthresh = tcb->cwind / 2;
  35.         tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  36.         /* Shrink congestion window to 1 packet */
  37.         tcb->cwind = tcb->mss;
  38.         tcp_output(tcb);
  39.     }
  40. }
  41. /* Backoff function - the subject of much research */
  42. backoff(n)
  43. int n;
  44. {
  45.     /* Use binary exponential up to retry #4, and quadratic after that
  46.      * This yields the sequence
  47.      * 1, 2, 4, 8, 16, 25, 36, 49, 64, 81, 100 ...
  48.      */
  49.  
  50.     if(n <= 4)
  51.         return 1 << n;    /* Binary exponential back off */
  52.     else
  53.         return n * n;    /* Quadratic back off */
  54. }
  55.  
  56.